const express = require('express');
const router = express.Router();
const gameController = require('../controllers/gameController');
const roomController = require('../controllers/roomController');
const { authenticateToken, requireKP } = require('../middleware/auth');
const { validateRoom, validateId, validateDiceCommand } = require('../middleware/validation');

// 创建游戏房间
router.post('/rooms', authenticateToken, validateRoom, roomController.createRoom);

// 获取房间列表
router.get('/rooms', authenticateToken, roomController.getRooms);

// 获取房间详情
router.get('/rooms/:roomId', authenticateToken, validateId, roomController.getRoom);

// 加入房间
router.post('/rooms/:roomId/join', authenticateToken, validateId, roomController.joinRoom);

// 离开房间
router.post('/rooms/:roomId/leave', authenticateToken, validateId, roomController.leaveRoom);

// 更新游戏状态（KP专用）
router.put('/rooms/:roomId/game-state', authenticateToken, validateId, requireKP, roomController.updateGameState);

// 更新地图数据（KP专用）
router.put('/rooms/:roomId/map-data', authenticateToken, validateId, requireKP, roomController.updateMapData);

// 强制掷骰（KP专用）
router.post('/rooms/:roomId/force-roll', authenticateToken, validateId, requireKP, validateDiceCommand, roomController.forceRoll);

// 修改角色属性（KP专用）
router.patch('/rooms/:roomId/character', authenticateToken, validateId, requireKP, roomController.modifyCharacter);

// 场景切换（KP专用）
router.post('/rooms/:roomId/scene', authenticateToken, validateId, requireKP, roomController.changeScene);

module.exports = router;
